package com.zhiyou100.blog.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

//@WebFilter(urlPatterns = {"/title/getDetail", "/title/addOne",
//        "/user_update.jsp", "/message/addOne"}
//        , dispatcherTypes = {DispatcherType.ERROR,
//        DispatcherType.FORWARD,
//        DispatcherType.INCLUDE, DispatcherType.REQUEST})
public class UserLoginFilter implements Filter {

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) arg0;
        if (req.getSession().getAttribute("loginUser") == null) {
            req.setAttribute("message", "只有登录才能访问！");
            req.getRequestDispatcher("/index.jsp").forward(req, arg1);
            return;
        }
        arg2.doFilter(req, arg1);

    }


}
